﻿using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.IO;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    internal class FtCblsData
    {
        private ushort _accel;
        private ushort _fChecked;
        private bool _fNo3D;

        public void Read(BinaryReader reader)
        {
            ushort ft = reader.ReadUInt16();
            Contract.Assert(ft == 0x0012);
            ushort cb = reader.ReadUInt16();
            Contract.Assert(cb == 0x0008);
            _fChecked = reader.ReadUInt16();
            _accel = reader.ReadUInt16();
            ushort reserved = reader.ReadUInt16();
            Contract.Assert(reserved == 0);
            ushort A = reader.ReadUInt16();

            _fNo3D = (A & 0x01) != 0;
        }

        public void Write(BinaryWriter writer)
        {
            ushort ft = 0x0012;
            writer.Write(ft);
            ushort cb = 0x0008;
            writer.Write(cb);
            writer.Write(_fChecked);
            writer.Write(_accel);
            writer.Write((ushort)0);
            if (_fNo3D)
                writer.Write((ushort)1);
            else
            {
                writer.Write((ushort)0);
            }
        }
    }
}